package com.cyc.basic.msb;

import java.util.Arrays;
import java.util.Random;

/**
 * @Description: 排序算法正确性验证器
 * @version 1.0
 * @author cyc
 * @date 2021/10/7 21:35
 */
public class DataChecker {

    /**
     * 生成一个指定数组长度的数组
     * @param arrLength 数组长度
     * @return arr
     */
    static int[] generateRandomArray(int arrLength) {
        Random r = new Random();
        int[] arr = new int[arrLength];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = r.nextInt(arrLength);
        }
        return arr;
    }

    /**
     * 检查排序算法是否正确
     */
    static void checkSelectionSort(int arrLength) {
        int[] arr = generateRandomArray(arrLength);
        int[] arr2 = new int[arr.length];
        System.arraycopy(arr, 0, arr2, 0, arr.length);

        Arrays.sort(arr);
//        SelectionSort.sort(arr2);
        DoubleSort.sort(arr2);
        boolean same = true;
        for (int i = 0; i < arr2.length; i++) {
            if (arr[i] != arr2[i]) {
                same = false;
            }
        }
        System.out.println(same == true ? "right" : "wrong");
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            checkSelectionSort(2000);
        }
    }
}
